package mc

import (
	"gitee.com/dreamwood/ez-go/db/mgo"
)

const (
	PaperEventNew          = "mes.PaperNew"
	PaperEventBeforeCreate = "mes.PaperBeforeCreate"
	PaperEventBeforeUpdate = "mes.PaperBeforeUpdate"
	PaperEventBeforeSave   = "mes.PaperBeforeCreate mes.PaperBeforeUpdate"
	PaperEventAfterCreate  = "mes.PaperAfterCreate"
	PaperEventAfterUpdate  = "mes.PaperAfterUpdate"
	PaperEventAfterSave    = "mes.PaperAfterCreate mes.PaperAfterUpdate"
	PaperEventDelete       = "mes.PaperDelete"

	PaperAccessControlEvent = "mes.PaperAccessControl"
)

func GetPaperConfig() *mgo.DocConfig {
	return Paper_Config
}

var Paper_Config *mgo.DocConfig

func init() {
	Paper_Config = NewPaperConfig()
}

func NewPaperConfig() *mgo.DocConfig {
	return &mgo.DocConfig{
		ContainerKey: "mes.Paper",
		Fields: []string{
			"plan", "sn", "flow", "process", "numSuccess", "numFail", "numWast", "emp", "srcPapers", "usedPapers", "numUsed",
		},
		RelationFields: []string{
			"flow", "process", "emp", "srcPapers", "usedPapers",
		},
		RelationConfigs: map[string]*mgo.DocRelation{

			"flow": {
				Config:     GetFlowConfig,
				DocName:    "Flow",
				JoinType:   "O",
				KeyInside:  "flowId",
				KeyOutSide: "id",
			},

			"process": {
				Config:     GetProcessConfig,
				DocName:    "Process",
				JoinType:   "O",
				KeyInside:  "processId",
				KeyOutSide: "id",
			},

			"emp": {
				Config:     GetEmpConfig,
				DocName:    "Emp",
				JoinType:   "O",
				KeyInside:  "empId",
				KeyOutSide: "id",
			},

			"srcPapers": {
				Config:     GetPaperLinksConfig,
				DocName:    "PaperLinks",
				JoinType:   "M",
				KeyInside:  "id",
				KeyOutSide: "destPaperId",
			},

			"usedPapers": {
				Config:     GetPaperLinksConfig,
				DocName:    "PaperLinks",
				JoinType:   "M",
				KeyInside:  "id",
				KeyOutSide: "srcPaperId",
			},
		},
		FieldFilter: map[string]*mgo.DocFieldFilter{
			"default": {
				Select: []string{},
				Omit:   []string{},
			},
		},
	}
}
